<template>
  <div>
    <el-container>
      <el-header>&nbsp;人力资源管理系统</el-header>
      <el-container class="container">
        <el-aside width="300px">
          <Menu>

          </Menu>
        </el-aside>
        <el-container>
          <el-main
              ref="salaryStandFile"
              :model="salaryStandFile"
              :rules="salaryStand"
          >
            <el-row>
              <el-col :span="22">
                <div class="grid-content bg-purple-dark">
                  <span>
                   薪酬标准登记
                  </span>
                </div>
              </el-col>
              <el-col :span="2">
                <div class="grid-content">
                  <el-button type="success" round @click="submitFile('salaryStandFile')">提交</el-button>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    薪酬标准编号
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandFile.salaryId" disabled placeholder="系统自动分配" clearable/>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    薪酬标准名称
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandFile.salaryName" placeholder="请填写标准名称" clearable/>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    薪酬总额
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandFile.total" disabled placeholder="系统自动计算" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    标准所属职位分类
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-select v-model="salaryStandFile.cjobId" placeholder="请选择" v-on:change="getJobName" style="width: 100%">
                    <el-option
                        v-for="item in salaryStand.JobClassification"
                        :label="item.cjobName"
                        :value="item.cjobId"
                    >
                    </el-option>
                  </el-select>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    标准所属职位名称
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-select v-model="salaryStandFile.njobId" placeholder="请选择" v-on:change="getJobTitle" style="width: 100%">
                    <el-option
                        v-for="item in salaryStand.JobName"
                        :label="item.njobName"
                        :value="item.njobId"
                    >
                    </el-option>
                  </el-select>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    标准所属职称
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-select v-model="salaryStandFile.tjobId" placeholder="请选择" style="width: 100%">
                    <el-option
                        v-for="item in salaryStand.JobTitle"
                        :label="item.tjobName"
                        :value="item.tjobId"
                    >
                    </el-option>
                  </el-select>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    制定人
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
<!--                  TODO 写好登录来写-->
                  <el-input v-model="salaryStandFile.maker" placeholder="请填写制定人" clearable/>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <span>
                    登记人
                  </span>
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandFile.registrant" disabled />
                </div>
              </el-col>
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  登记时间
                </div>
              </el-col>
              <el-col :span="5">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="salaryStandFile.createTime" disabled placeholder="系统自动填写" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    序号
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    薪酬项目名称
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    金额
                  </span>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    1
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    基本工资
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.basic" placeholder="请填写基本工资" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    2
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    交通补助
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.transportation" placeholder="请填写交通补助" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    3
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    午餐补助
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.lunch" placeholder="请填写午餐补助" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    4
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    通信补助
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.communication" placeholder="请填写通信补助" v-on:change="updateSalary" clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    5
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    养老保险
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.endowment" placeholder="系统自动计算" disabled clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    6
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    失业保险
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.unemployment" placeholder="系统自动计算" disabled clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    7
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    医疗保险
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.medical" placeholder="系统自动计算" disabled clearable/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <span>
                    8
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <span>
                    住房公积金
                  </span>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input v-model="salaryStandFile.providentFund" placeholder="系统自动计算" disabled clearable/>
                </div>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>

import{ defineComponent, ref }from 'vue'
import {
  Location,
  Document,
  Menu as IconMenu,
  Setting,
} from '@element-plus/icons-vue'
import Menu from "@/components/Menu";
import {mapState} from "vuex";
export default defineComponent({
  name: "SalaryStandardRegistration",
  components: {
    Menu,
    Location,
    Document,
    Setting,
    IconMenu,
  },
  setup() {
    const activeNames = ref(['1'])
    const handleChange = (val) => {
      console.log(val)
    }

    return {
      activeNames,
      handleChange,
    }
  },
  data() {
    return {
      salaryStandFile: {
        salaryId: '',
        salaryName: '',
        cjobId: '',
        njobId: '',
        tjobId: '',
        total: '',
        maker: '',
        registrant: '',
        createTime: '',
        basic: '',
        transportation: '',
        lunch: '',
        communication: '',
        endowment: '',
        unemployment: '',
        medical: '',
        providentFund: '',
      },
      salaryStand: {
        JobClassification: null,
        cjobName: null,
        cjobId: null,
        JobName: null,
        njobName: null,
        njobId: null,
        JobTitle: null,
        tjobName: null,
        tjobId: null,
      }
    }
  },
  computed: {
    ...mapState({
      registrantInfo: state => state.user.uname, // 假设 user.uname 是登记人信息
    }),
  },
  watch: {
    registrantInfo(newVal) {
      this.salaryStandFile.registrant = newVal;
    },
  },
  mounted() {
    this.salaryStandFile.registrant = this.registrantInfo; // 初始赋值
  },
  methods: {
    submitFile(forName) {
      const _this = this
      this.axios.post('/salary/add',this.salaryStandFile).then(res =>{
        alert("操作成功")
      })
    },
    updateSalary() {
      this.salaryStandFile.endowment = Number(this.salaryStandFile.basic*0.08)
      this.salaryStandFile.medical = Number((this.salaryStandFile.basic*0.02) + 3)
      this.salaryStandFile.unemployment = Number(this.salaryStandFile.basic*0.005)
      this.salaryStandFile.providentFund = Number(this.salaryStandFile.basic*0.08)
      this.salaryStandFile.total = Number(this.salaryStandFile.basic) +
                                   Number(this.salaryStandFile.transportation) +
                                   Number(this.salaryStandFile.lunch) +
                                   Number(this.salaryStandFile.communication) +
                                   Number(this.salaryStandFile.endowment) +
                                   Number(this.salaryStandFile.medical) +
                                   Number(this.salaryStandFile.unemployment) +
                                   Number(this.salaryStandFile.providentFund)
    },

    getJobClassification() {
      this.axios.get('/selectJobClassification').then(res =>{
        const _this = this
        _this.salaryStand.JobClassification = res.data.data
      })
    },
    getJobName() {
      this.salaryStandFile.njobId = null
      this.salaryStandFile.tjobId = null
      this.axios.get('/selectJobName/'+ this.salaryStandFile.cjobId).then(res =>{
        const _this = this
        _this.salaryStand.JobName = res.data.data
      })
    },
    getJobTitle() {
      this.salaryStandFile.tjobId = null
      this.axios.get('/selectJobTitle/'+ this.salaryStandFile.njobId).then(res =>{
        const _this = this
        _this.salaryStand.JobTitle = res.data.data
      })
    }
  },
  created() {
    this.getJobClassification()
  }
})
</script>

<style scoped>
.el-header{
  background-color: #409EFF;
  color: #e9eef3;
  text-align: left;
  line-height: 60px;
  font-size: 30px;
}
.el-aside {
  background-color: #d3dce6;
  color: var(--el-text-color-primary);
  text-align: center;
  /*line-height: 860px;*/
}

.el-main {
  background-color: #e9eef3;
  color: var(--el-text-color-primary);
  text-align: center;
  line-height: 30px;
}

body > .el-container {
  margin-bottom: 400px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-row {
  margin-bottom: 20px;
}

.el-row :last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.high-row{
  min-height: 200px;
}

.container{
  min-height: 860px;
}

.line {
  width: 70%;
}

.line div {
  width: 100%;
  height: 0;
  border-top: 1px solid var(--el-border-color-base);
}

</style>